#/usr/env/bin python

import commands

def monitor():
	shell_command = 'free -m |grep "^Mem"'
	status,result = commands.getstatusoutput(shell_command)

	if status != 0 :
		value_dic ={'status':status}
	else:
		value_dic = {}
		total,used,free,shared,buffers,cached = result.split()[1:]
		usage = ((float(total) - float(free)-float(buffers)-float(cached))/float(total))*100
		value_dic={
			'total':total,
			'used':used,
			'free':free,
			'shared':shared,
			'buffers': buffers,
			'cached':cached,
			'status':status,
			'usage':usage,
		}
	
	return value_dic


if __name__ == "__main__":
	print monitor()
